package com.atguigu.gulimall.cart.vo;


import java.math.BigDecimal;
import java.util.List;

/**
 * 整个购物车
 */
public class Cart {

    List<CartItem> cartItems;

    private Integer countNum;//商品的数量

    private Integer countType;//商品类型数量

    private BigDecimal totalAmount;//商品的总价

    private BigDecimal reduce=new BigDecimal("0");//减免价格

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getCountNum() {
        int count=0;
        if (cartItems!=null && cartItems.size()>0){
            for (CartItem item : cartItems) {
                count+=item.getCount();
            }
        }
        return count;
    }


    public Integer getCountType() {
        int count=0;
        if (cartItems!=null && cartItems.size()>0){
            for (CartItem item : cartItems) {
                count+=1;
            }
        }
        return count;
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount=new BigDecimal("0");
        //计算购物项总价
        if (cartItems!=null && cartItems.size()>0){
            for (CartItem item : cartItems) {
                if (item.getCheck()){
                    amount=amount.add(item.getTotalPrice());
                }
            }
        }
        //减去优惠总价
        BigDecimal subtract = amount.subtract(getReduce());
        return subtract;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
